package thread;

//runnable是一个接口，所以用实现的方式
//往往是继承一个类实现多接口
class MyRunnable implements Runnable{
    @Override
    public void run(){
        //描述了线程要完成的逻辑是啥
        while (true){
            System.out.println("hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Demo2 {
    public static void main(String[] args) {
        MyRunnable runnable=new MyRunnable();
        //真正创建线程还是要通过Thread作为载体进行创建
        Thread t=new Thread(runnable);
        t.start();

        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
